package com.cskaoyan.gateway.controller.order;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.order.OrderDeleteService;
import com.mall.order.constant.OrderRetCode;
import com.mall.order.dto.DeleteOrderRequest;
import com.mall.order.dto.DeleteOrderResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Connor
 * @date 2020/12/21
 */
@RestController
@RequestMapping("shopping")
public class DeleteController {

    @Reference(timeout = 3000,check = false)
    private OrderDeleteService orderDeleteService;

    @DeleteMapping("order/{id}")
    public ResponseData delete(@PathVariable(name = "id") String id) {

        DeleteOrderRequest deleteOrderRequest = new DeleteOrderRequest(id);
        DeleteOrderResponse deleteOrderResponse = orderDeleteService.deleteOrder(deleteOrderRequest);
       /* if (deleteOrderResponse.getCode().equals(OrderRetCode.REQUISITE_PARAMETER_NOT_EXIST.getCode())) {
            return new ResponseUtil<String>().setErrorMsg(deleteOrderResponse.getMsg());
        }*/
        if (deleteOrderResponse.getCode().equals(OrderRetCode.SUCCESS.getCode())) {
            return new ResponseUtil<>().setData(deleteOrderResponse.getCode(), deleteOrderResponse.getMsg());
        }
        return new ResponseUtil<>().setErrorMsg(OrderRetCode.DB_EXCEPTION.getMessage());
    }
}
